package com.rtx.wms.customer.grp.job.asn;

import java.util.List;

import org.quartz.DisallowConcurrentExecution;
import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.rtx.api.annotation.RtxJobAnnotation;
import com.rtx.api.quartz.job.BaseJob;
import com.rtx.edi.model.api.bo.ApiMappingInfoBo;
import com.rtx.edi.platform.baseinfo.service.PlApiService;
import com.rtx.wms.customer.grp.handler.qcapply.GrpQcApplyHandle;
import com.rtx.wms.std.common.bean.WmsConstant;
import com.rtx.wms.std.common.service.CommonService;

@Component
@DisallowConcurrentExecution
@RtxJobAnnotation(jobName = "GrpQcApplyJob",description = "格瑞普复检申请",cron = "0/10 * * * * ?")
public class GrpQcApplyJob implements BaseJob {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private GrpQcApplyHandle grpQcApplyHandle;

    @Autowired
    private CommonService commonService;
    
    @Autowired
    PlApiService plApiService;

    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException {
        //激活的仓库
        List<String> whseidList = commonService.selectActiveWhseidNotEnterprise(WmsConstant.ENTERPRISE);
        for(String whseid : whseidList){
            try {
        		JobDataMap dataMap = context.getJobDetail().getJobDataMap();
        		
        		String mappingCode = dataMap.get("apiMappingCode")+"";
        		
        		ApiMappingInfoBo bo = plApiService.getApiMappingInfo(mappingCode);
        		
        		grpQcApplyHandle.handlerUpload("wmwhse1",bo);
            } catch (Exception e) {
                logger.error("仓库{}出库单回传异常",whseid,e);
            }
        }
    }
}
